package com.zzyl.serve.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.domain.PageVo;
import com.zzyl.serve.dto.MemberFamilyDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.dto.queryDeviceDataListByDayDto;
import com.zzyl.serve.vo.DeviceDataVo;
import com.zzyl.serve.vo.LoginVo;
import com.zzyl.serve.vo.MyFamilyVo;
import com.zzyl.serve.vo.QueryServiceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.FamilyMember;
import com.zzyl.serve.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 小程序端 用户登录
     */
	@PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);
        return R.ok(vo);
    }

    /**
     * 1.1 绑定家人
     * 注意：此接口绑定的是入住的老人，详细逻辑处理一定要查看【产品原型】完成；
     * 接口地址:/member/user/add
     * 请求方式:POST
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody MemberFamilyDto dto, HttpServletRequest request){
        
        familyMemberService.addFamily(dto, request);
        return AjaxResult.success();
    }

    /**
     * 1.2 查询家人列表
     * 接口地址:/member/user/my
     * 请求方式:GET
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult my(HttpServletRequest request){
      List<MyFamilyVo> list  = familyMemberService.my(request);
        return AjaxResult.success(list);
    }

    /**
     * 1.3 查看家人列表（分页查询）
     * 接口地址:/member/user/list-by-page
     * 请求方式:GET
     */
    @GetMapping("/list-by-page")
    @ApiOperation("查看家人列表（分页查询）")
    public AjaxResult listByPage(HttpServletRequest request){
        startPage();
        List<PageVo> list  = familyMemberService.listByPage(request);
        return AjaxResult.success(list);
    }

    /**
     *
     * 1.4 查询健康数据
     * 接口地址:/member/user/queryServiceProperties/{iotId}    （新小程序，用这个）
     * 请求方式:GET
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId){
        List<QueryServiceVo> list = familyMemberService.queryServiceProperties(iotId);
        return AjaxResult.success(list);
    }

    /*
* 1.5  按天统计查询指标数据
接口地址:/member/user/queryDeviceDataListByDay
请求方式:GET
* */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(queryDeviceDataListByDayDto vo){
        List<DeviceDataVo> list = familyMemberService.queryDeviceDataListByDay(vo);
        return AjaxResult.success(list);
    }

    /*
    * 1.6 按周统计查询指标数据
    接口地址:/member/user/queryDeviceDataListByWeek
    请求方式:GET
    * */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(queryDeviceDataListByDayDto vo){
        List<DeviceDataVo> list =  familyMemberService.queryDeviceDataListByWeek(vo);
        return AjaxResult.success(list);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
